import { useLayoutEffect, useState } from "react";

export const isMobile = () => {
  const screenWidth= window.innerWidth <= 760;
  const [mobile, setMobile] = useState<boolean>(screenWidth);

  const userAgent = () => {
    const userAgent = navigator.userAgent.match(
      /(iPhone|iPod|Android|ios|iPad|AppleWebKit.*Mobile.*)/i
    );
    userAgent ? setMobile(true) : setMobile(false);
  };
  useLayoutEffect(() => {
    window.addEventListener("resize", userAgent);
    return () => {
      window.removeEventListener("resize", userAgent);
    };
  }, []);
  return mobile;
};
